﻿using System;
using System.Collections.Generic;
using System.Text;
using YouHP.Utility;
using YouHP.BLL;
using YouHP.Model;
using YouHP.Logic;

namespace YouHP.Pages.Profile
{
    public class ProfileBasePage : YouHP.Pages.BasePage
    {
        protected override void ShowPage()
        {
            base.ShowPage();

            int uid = RequestTools.GetInt("uid", 0);
            if (uid <= 0)
            {
                this.AddErrLine("无效的 uid ");
                return;
            }

            ProfileData = UserBLL.Instance.GetUserInfo(uid);
            if (ProfileData.Id <= 0)
            {
                this.AddErrLine("找不到用户");
                this.SetTitle("病情系统");
                return;
            }

            PrData = PatientBLL.Instance.GetPatientRecordInfo(ProfileData.Id);
            //得到最近n个访问用户列表
            LattestVisitRecordList = UserBLL.Instance.GetLattestVisitRecordList(ProfileData.Id, n);
            //取得相同疾病的n个用户
            PatientDataListRelate = PatientBLL.Instance.GetHottestPatientByDisease(PrData.DiseaseId, n);


            this.AddLocation(
                string.Format("<font color=red>{0} 的病情系统</font>",ProfileData.UserName),
                string.Format("/Profile/Index.aspx?uid={0}",ProfileData.Id)
                );
            int count = 0;


            IsSpace = (PageKey == PageKeys.Profile_Index);
    
            IsCondition =  (PageKey == PageKeys.Profile_Condition);       	                     	                
    
            IsLog = (PageKey == PageKeys.Profile_LogList 
                || PageKey == PageKeys.Profile_Log 
                || PageKey == PageKeys.Profile_LogCommentAdd
                || PageKey == PageKeys.Profile_LogCommentList );
            
            IsComment = (PageKey == PageKeys.Profile_CommentAdd 
                || PageKey == PageKeys.Profile_CommentList); 
            
            IsAction = (PageKey == PageKeys.Profile_ActionAdd 
                || PageKey == PageKeys.Profile_ActionList);
            
            IsFriend = (PageKey == PageKeys.Profile_FriendList);

            IsGroup = (PageKey == PageKeys.Profile_GroupList);



            if (IsLog == false)
            {
                LogDataListBase = LogTopicBLL.Instance.GetLogTopicList(6, 1, ProfileData.Id, out count);
                LogCommentLattest = LogCommentBLL.Instance.GetLattestLogCommentByUser(6, ProfileData.Id);
            }
            if (IsComment == false)
            {
                CommentDataListBase = CommentBLL.Instance.GetCommentList(6, 1, ProfileData.Id, out count);
            }
            if (IsFriend == false)
            {
                FriendDataListBase = FriendBLL.Instance.GetFriendList(6, 1, ProfileData.Id, Constants.FriendPass, out count);
            }
            if (IsAction == false)
            {
                ActionDataListBase = ActionBLL.Instance.GetHugBookList(6, 1, ProfileData.Id, out count);
            }

            EmotionLogic    emotionLogic = new EmotionLogic();
            allEmotionTypes = emotionLogic.GetAllEmotionTypes();
            emotionData = emotionLogic.GetEmotion(uid);
        }

        protected UserInfo ProfileData;
        protected PatientRecordInfo PrData;
        protected List<LogTopicInfo> LogDataListBase;
        protected List<LogCommentInfo> LogCommentLattest;
        protected List<CommentInfo> CommentDataListBase;
        protected List<ActionInfo> ActionDataListBase;
        protected List<UserInfo> FriendDataListBase;
        protected List<VisitRecordInfo> LattestVisitRecordList;
        protected List<UserInfo> PatientDataListRelate;
        protected int n = 6;

        protected bool IsLog;
        protected bool IsComment;
        protected bool IsFriend;
        protected bool IsAction;
        protected bool IsSpace;
        protected bool IsCondition;
        protected bool IsGroup;

        public string StartDateStr
        {
            get
            {
                if (PrData.StartDate != null &&
                    PrData.StartDate.CompareTo(new DateTime(1920, 1, 1)) > 0 &&
                    PrData.StartDate.CompareTo(new DateTime(2100, 1, 1)) < 0)
                {
                    return PrData.StartDate.ToString("yyyy-MM-dd");
                }
                else
                {
                    return "未知";
                }
            }
        }

        public string ConfirmDateStr
        {
            get
            {
                if (PrData.ConfirmDate != null &&
                    PrData.ConfirmDate.CompareTo(new DateTime(1920, 1, 1)) > 0 &&
                    PrData.ConfirmDate.CompareTo(new DateTime(2100, 1, 1)) < 0)
                {
                    return PrData.ConfirmDate.ToString("yyyy-MM-dd");
                }
                else
                {
                    return "未知";
                }
            }
        }

        // 心情系统数据
        public List<EmotionTypeInfo> allEmotionTypes;
        public EmotionInfo emotionData;
        public string EmotionImgURL
        {
            get
            {
                if (emotionData == null || emotionData.EmotionTypeData == null || emotionData.EmotionTypeData.Img == "")
                {
                    // return a default one.
                    EmotionLogic emotionLogic = new EmotionLogic();
                    List<EmotionTypeInfo> allEmotionTypes = emotionLogic.GetAllEmotionTypes();
                    if (allEmotionTypes.Count == 0)
                        return "";
                    else
                        return allEmotionTypes[0].Img;
                }
                else
                    return emotionData.EmotionTypeData.Img;
            }
        }
        public string EmotionDescriptionStr
        {
            get
            {
                if (emotionData == null || emotionData.StatusDescription == "")
                    return "没有什么好说的...";
                else
                    return emotionData.StatusDescription;
            }
        }
    }
}
